package com.jwj.testback.backups.dao;

import com.jwj.testback.backups.pojo.MysqlBackups;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * MySQL数据备份表 Mapper 接口
 * </p>
 *
 * @author JWJ
 * @since 2021-12-07
 */
public interface MysqlBackupsMapper extends BaseMapper<MysqlBackups> {
//    CREATE TABLE #{newTable_name} AS #{oldTable_name}

    //复制表结构及索引
    @Select("CREATE TABLE ${newTable_name} LIKE ${oldTable_name}")
    String addTable(String newTable_name,String oldTable_name);

    //查找表
    @Select("SHOW TABLES LIKE #{newTable_name}")
    String findTable(String newTable_name);

    //删除表
    @Select("DROP TABLE ${newTable_name}")
    String delNewT(String newTable_name);

    //根据时间复制数据到新表中
    @Select("INSERT INTO ${newTable_name} SELECT * FROM ${oldTable_name} WHERE ${timeField} >= #{start} and create_date < #{end}")
    String addBase(String newTable_name, String oldTable_name,String timeField, String start, String end);


    //查询总数据数量
    @Select("SELECT COUNT(*) FROM ${table}")
    int count(String table);

    //按时间查询数据总数
    @Select("SELECT COUNT(*) FROM ${table} WHERE ${timeField} >= #{start} and create_date < #{end}")
    int countWhe(String table,String timeField, String start, String end);

    //显示所有表
    @Select("SHOW TABLES")
    List<String> showTables();

}
